import datetime
import uuid

from django.db import models
from personal_center.models import User
# Create your models here.
from Administrative_office_system.utils.BaseModel import BaseModel, TimeStampFileName, ChatStampFileName, \
    IssueStampFileName



class OpLogs(models.Model):
    """操作日志表"""
    id = models.AutoField(primary_key=True)
    re_time = models.CharField(max_length=32, verbose_name='请求时间')
    re_user = models.CharField(max_length=32, verbose_name='操作人')
    re_ip = models.CharField(max_length=32, verbose_name='请求IP')
    re_url = models.CharField(max_length=255, verbose_name='请求url')
    re_method = models.CharField(max_length=11, verbose_name='请求方法')
    re_content = models.TextField(null=True, verbose_name='请求参数')
    flow_name = models.CharField(max_length=255, verbose_name='流程名称', default="")

    class Meta:
        db_table = 'access_logs'

class AccessTimeOutLogs(models.Model):
    """超时操作日志表"""
    id = models.AutoField(primary_key=True)
    re_time = models.CharField(max_length=32, verbose_name='请求时间')
    re_user = models.CharField(max_length=32, verbose_name='操作人')
    re_ip = models.CharField(max_length=32, verbose_name='请求IP')
    re_url = models.CharField(max_length=255, verbose_name='请求url')
    re_method = models.CharField(max_length=11, verbose_name='请求方法')
    re_content = models.TextField(null=True, verbose_name='请求参数')

    class Meta:
        db_table = 'access_timeout_logs'


class OaMeeting(BaseModel):
    # 会议室名称 会议室地址 可容纳人数 会议室地址 配置资源
    user_id = models.IntegerField(verbose_name="用户表id")
    title = models.CharField(max_length=32, verbose_name="会议标题")
    start_time = models.CharField(max_length=20, verbose_name="会议开始时间")
    finish_time = models.CharField(max_length=20, verbose_name="会议结束时间")
    host_name = models.CharField(max_length=20, verbose_name="支持人")
    propocer = models.CharField(max_length=20, verbose_name="申请人")
    content = models.TextField(verbose_name="会议内容")
    current_status = models.CharField(max_length=32, verbose_name="目前状态")
    is_deleted = models.BooleanField(default=False, verbose_name="逻辑删除")

    class Meta:
        db_table = 'oa_meeting'
        verbose_name = '会议'
        verbose_name_plural = verbose_name
        ordering = ['-update_time']


class OaMeetingRoom(BaseModel):
    # meeting_id = models.IntegerField(verbose_name="会议id")
    room_name = models.CharField(max_length=32, verbose_name="会议室名称")
    id_deleted = models.BooleanField(default=False, verbose_name="逻辑删除")
    des = models.CharField(max_length=255, verbose_name="会议内容")
    capacity = models.CharField(max_length=32, verbose_name="可容纳人数")
    site = models.CharField(max_length=255, verbose_name="会议室地址")
    resources = models.CharField(max_length=255, verbose_name="配置资源")

    class Meta:
        db_table = 'oa_meeting_room'
        verbose_name = "会议室"


class OaMeetingUser(BaseModel):
    meeting_id = models.IntegerField(verbose_name="会议id")
    user_id = models.IntegerField(verbose_name="人员id")

    class Meta:
        db_table = "oa_meeting_user"
        verbose_name = "参会人员"


class MeetingInfo(BaseModel):
    """
    会议情况
    """
    application_id = models.CharField(max_length=128, verbose_name='申请表id')
    meeting_room = models.CharField(default='', max_length=128, verbose_name='会议室名')
    meeting_theme = models.CharField(default='', max_length=128, verbose_name='会议主题')
    username = models.CharField(max_length=128, verbose_name='申请人账号')
    real_name = models.CharField(max_length=128, verbose_name='申请人姓名')
    start_time = models.DateTimeField(blank=True, null=True, verbose_name='开始会议时间')
    end_time = models.DateTimeField(blank=True, null=True, verbose_name='结束会议时间')
    minutes = models.TextField(max_length=128, verbose_name='会议笔记')
    marks = models.CharField(max_length=255, verbose_name="会议申请时备注")
    status = models.CharField(max_length=128, verbose_name='会议室状态：1.空闲，2.使用中，3.预定中，4.驳回', default="1")
    Inform_personnel = models.TextField(verbose_name="知会人员列表", default='')

    class Meta:
        db_table = 'tb_MeetingInfo'
        verbose_name = '会议信息'
        verbose_name_plural = verbose_name
        ordering = ['-update_time']


class MeetingInfoFile(BaseModel):
    """
       会议文件
    """
    application_id = models.CharField(max_length=128, verbose_name='申请表id')
    room_id = models.CharField(max_length=128, verbose_name='会议室id')
    Info_id = models.CharField(max_length=128, verbose_name='会议表id')
    file_size = models.CharField(default='', max_length=128, verbose_name='文件大小')
    uploader = models.CharField(default='', max_length=128, verbose_name='上传人')
    file_path = models.FileField(default='', upload_to=ChatStampFileName(r'MeetingFile/'), )


class CarInfoFile(BaseModel):
    """
       车辆文件
    """
    Info_id = models.CharField(max_length=128, verbose_name='车辆id')
    file_size = models.CharField(max_length=128, verbose_name='文件大小')
    file_path = models.FileField(default='', upload_to=ChatStampFileName(r'CarFile/'), )
    uploader = models.CharField(max_length=128, verbose_name='上传人')


class IssueApproval(BaseModel):
    """
    议题审批
    """
    issue_number = models.CharField(max_length=128, verbose_name='议题编号')
    issue_type = models.CharField(default='', max_length=128, verbose_name='议题类型,1:院长办公会议，2:党委会议')
    issue_year = models.CharField(max_length=128, verbose_name='议题年份')
    issue_year_number = models.CharField(default='', max_length=128, verbose_name='议题年份数字')
    submitter = models.CharField(default='', max_length=128, verbose_name='提交人')
    submission_department = models.CharField(max_length=128, verbose_name='提交部门')
    in_charge_signature = models.CharField(max_length=128, verbose_name='负责人签字')
    in_charge_status = models.CharField(default='0', max_length=128, verbose_name='提交部门状态,0:未处理 1:同意 2:不同意')
    submission_date = models.CharField(max_length=128, verbose_name='提交日期')
    topics = models.CharField(max_length=128, verbose_name='议题')
    key_issues = models.TextField(max_length=128, verbose_name='议题要点')
    leader = models.CharField(default='', max_length=128, verbose_name='分管领导')
    in_charger = models.CharField(default='', max_length=128, verbose_name='提交部门负责人')
    leader_opinion = models.TextField(verbose_name='分管领导意见')
    leader_opinion_time = models.CharField(max_length=128, verbose_name='分管领导意见时间')
    main_opinion = models.TextField(default='', verbose_name='主要负责人意见')
    main_opinion_time = models.CharField(default='', max_length=128, verbose_name='主要负责人时间')
    processing_result = models.CharField(max_length=128, verbose_name='处理结果')
    co_organizing_department = models.TextField(verbose_name='协办部门')
    to_do_list = models.CharField(default='', max_length=255, verbose_name='待办名单')
    now_flow = models.CharField(default='', max_length=255, verbose_name='当前节点')
    status_dict = models.TextField(default='', verbose_name='流程状态')
    reject_dict = models.TextField(default='', verbose_name='未通过的状态')
    issue_sketch_dict = models.TextField(default='', verbose_name='议题主要内容')


class IssueInfoFile(BaseModel):
    """
       议题文件
    """
    Info_id = models.CharField(max_length=128, verbose_name='车辆id')
    file_size = models.CharField(max_length=128, verbose_name='文件大小')
    file_path = models.FileField(default='', upload_to=IssueStampFileName(r'issueFile/'))
    uploader = models.CharField(max_length=128, verbose_name='上传人')
    file_type = models.CharField(default='', max_length=128, verbose_name='文件类型：0：正文，1 附件')


class Company(BaseModel):
    '''科室'''
    name = models.CharField(max_length=50, verbose_name='名称')
    parent_id = models.ForeignKey('self', verbose_name="上级部门", blank=True, null=True, on_delete=models.CASCADE)
    director = models.CharField(default='', max_length=50, verbose_name="主任")
    deputy_director = models.CharField(default='', max_length=50, verbose_name="副主任")
    head_nurse = models.CharField(default='', max_length=50, verbose_name="护士长")
    leaders = models.CharField(default='', max_length=50, verbose_name="分管领导")
    abbreviation = models.CharField(max_length=50, verbose_name="拼音简称", blank=True)
    serial_number = models.IntegerField(default=0, verbose_name='序号')
    head_people = models.ForeignKey('personal_center.User', verbose_name="负责人", blank=True, null=True, related_name='head_user', on_delete=models.CASCADE)
    director_id = models.ForeignKey('personal_center.User', verbose_name="主任", blank=True, null=True, related_name='director_user', on_delete=models.CASCADE)
    head_nurse_id = models.ForeignKey('personal_center.User', verbose_name="护士长", blank=True, null=True, related_name='head_nurse_user', on_delete=models.CASCADE)
    deputy_director_ids = models.ManyToManyField('personal_center.User', verbose_name='副主任', related_name='deputy_director_users', blank=True)
    leaders_id = models.ForeignKey('personal_center.User', verbose_name="分管领导", blank=True, null=True, related_name='leaders_user', on_delete=models.CASCADE)
    is_functional = models.BooleanField(default=False, verbose_name="是否职能科室")
    show = models.CharField(default='1', max_length=10, verbose_name="是否展示")

    class Meta:
        verbose_name = "部门"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Topics(BaseModel):
    '''议题'''
    STATE = (
        ('cg', '草稿'),
        ('draft', '分管领导审核'),
        ('OPR', '办公室初审'),
        ('confirm', '院办/党办主任审核'),
        ('audit', '院长/书记审核'),
        ('yd_leader', '院办分管领导审核'),
        ('db_leader', '党办分管领导审核'),
        ('yb', '院长办公室'),
        ('sj', '书记审核'),
        ('done', '结束'),
        ('unmetting', '待上会'),
        ('metting', '已上会'),
        ('shelve', '搁置'),
        ('refuse', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
        ('db_one_step', '转会第一步'),
        ('db_two_step', '转会第二步'),
        ('db_three_step', '转会第三步'),
        ('db_four_step', '转会第四步'),
    )
    TYPE = (
        ('db', '党办'),
        ('yb', '院办'),
        ('xz', '行政')
    )
    MEET = (
        ('a', '待上会'),
        ('b', '已上会'),
        ('c', '废弃')
    )
    TopicType = (
        ('1', '付款类'),
        ('2', '经济合同类'),
        ('3', '项目类'),
        ('4', '文件类'),
        ('5', '方案类'),
        ('6', '其他事项'),
    )
    ContractType = (
        ('1', '服务类'),
        ('2', '货物类'),
        ('3', '工程类'),
        ('4', '其他类'),
    )
    PayType = (
        ('1', '合同付款'),
        ('2', '固定资产/维修维保付款'),
        ('3', '材料付款'),
        ('4', '餐补付款'),
        ('5', '学科经费'),
        ('6', '科研经费'),
        ('7', '一般付款'),
        ('8', '工会付款'),
    )
    FundingSource = (
        ('1', '自有经费'),
        ('2', '学科经费'),
        ('3', '科研经费'),
        ('4', '财政拨款'),
        ('5', '贴息贷款'),
        ('6', '专项债券'),
        ('7', '工会经费'),
    )

    employee = models.ForeignKey(
        'personal_center.User',
        verbose_name="提交人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    fg_people = models.ForeignKey(
        'personal_center.User',
        related_name='topics_fg_people',
        verbose_name="分管领导",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    company = models.ForeignKey('Company', verbose_name="申请科室", blank=False, null=True, on_delete=models.CASCADE)
    type = models.CharField('类型', max_length=10, choices=TYPE, default='db')
    number = models.CharField(max_length=50, verbose_name='议题编号')
    state = models.CharField('状态', max_length=20, choices=STATE, default='draft')
    topic_type = models.CharField('议题类型', max_length=10, choices=TopicType, default='')
    pay_type = models.CharField('付款类型', max_length=10, choices=PayType, default='')
    whether_outweigh = models.CharField('是否超过20万', max_length=10, default='')
    contract_type = models.CharField('合同类型', max_length=10, choices=ContractType, default='')
    contract_name = models.CharField('合同名称', max_length=255, default='')
    contract_number = models.CharField('合同编号', max_length=255, default='')
    Payee = models.CharField('收款单位', max_length=255, default='')
    receiving_account = models.CharField('收款账号', max_length=255, default='')
    opening_bank = models.CharField('开户行', max_length=255, default='')
    funding_source = models.CharField('经费来源', max_length=10, choices=FundingSource, default='')
    amount_words = models.CharField('金额大写', max_length=255, default='')
    application_amount = models.CharField('申请金额', max_length=255, default='')
    whether_bid = models.CharField('是否招标', max_length=10, default='')
    topics_name = models.TextField(verbose_name='议题名称')
    topics_text = models.TextField(max_length=128, verbose_name='议题内容')
    topics_basis = models.TextField(max_length=128, verbose_name='议题依据', blank=True)
    solution = models.TextField(max_length=128, verbose_name='解决方案', blank=True)
    db_topics_text = models.TextField(verbose_name='党办议题内容', null=True)
    db_topics_basis = models.TextField(verbose_name='党办议题依据', blank=True, null=True)
    db_solution = models.TextField(verbose_name='党办解决方案', blank=True, null=True)
    topics_estimate = models.CharField(max_length=128, verbose_name='议题预估', blank=True)
    help_department = models.ManyToManyField('Company', related_name='topics_help_department', verbose_name='协办科室', blank=True)
    attachments = models.TextField(verbose_name="附件", blank=True)
    topics_attachments = models.TextField(verbose_name="议题正文", blank=True)
    current_audit_user = models.CharField('当前审批人', max_length=10, default='')
    meetings_num = models.CharField('议题会议召开次数', max_length=10, default='0')
    already_users = models.ManyToManyField('personal_center.User', verbose_name='已办人员', related_name='topics_already_users', blank=True)
    is_yb = models.BooleanField(default=False, verbose_name='是否经过院办')  # true 经过院办 false 不经过院办
    is_meeting = models.CharField('是否上会', max_length=10, choices=MEET, default='a')
    nrwb = models.TextField(verbose_name='议题内容纯文本', default='')
    zcwb = models.TextField(verbose_name='政策依据纯文本', default='')
    fawb = models.TextField(verbose_name='解决方案纯文本', default='')
    db_nrwb = models.TextField(verbose_name='党办议题内容纯文本', default='', null=True)
    db_zcwb = models.TextField(verbose_name='党办政策依据纯文本', default='', null=True)
    db_fawb = models.TextField(verbose_name='党办解决方案纯文本', default='', null=True)
    ysje = models.CharField(max_length=128, verbose_name='预算金额', default='', null=True)
    jfly = models.CharField(max_length=128, verbose_name='经费来源', default='', null=True)
    HouseToParty_id = models.CharField(max_length=50, verbose_name='院转党，院办ID', default='', null=True)
    TransferReturn = models.CharField(max_length=10, verbose_name='转会退回', default='0', null=True)
    public_search = models.ForeignKey('PublicSearch', verbose_name="搜索表", blank=True, null=True, on_delete=models.CASCADE)
    received_foreign = models.ForeignKey('OfficialDocuments', verbose_name="上级来文", blank=True, null=True, default='', on_delete=models.CASCADE)
    uuid = models.CharField(max_length=128, verbose_name='uuid', default='', null=True)
    is_audit = models.BooleanField(default=True, verbose_name='是否可以点击通过')
    iss_year = models.CharField(max_length=50, verbose_name='议题上会年份', default='2022')
    last_state = models.CharField(max_length=50, verbose_name='搁置之前的状态', default='')
    # current_audit_user = models.ForeignKey(
    #     'personal_center.User',
    #     verbose_name="当前审批人",
    #     blank=True,
    #     null=True,
    #     related_name='topics_current_audit_user',
    #     on_delete=models.CASCADE)
    # vice_company = models.ManyToManyField('Company', related_name='Topics_vice_company', verbose_name='抄送科室', blank=True)
    class Meta:
        verbose_name = '议题管理'
        verbose_name_plural = verbose_name

    def get_state_str(self):
        if self.state == 'done':
            return '结束'
        elif self.state == 'refuse':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'unmetting':
            return '待上会'
        elif self.state == 'metting':
            return '已上会'
        elif self.state == 'shelve':
            return '搁置'
        elif self.state == 'cg':
            return '草稿'
        else:
            return '审核中'

    def get_state_str1(self):
        if self.state == 'done':
            return '结束'
        elif self.state == 'refuse':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'unmetting':
            return '待上会'
        elif self.state == 'metting':
            return '已上会'
        elif self.state == 'shelve':
            return '搁置'
        elif self.state == 'cg':
            return '草稿'
        elif self.state == 'draft':
            return '分管领导'
        elif self.state == 'confirm':
            return '院办/党办主任'
        elif self.state == 'audit':
            return '院长/书记'
        elif self.state == 'yd_leader':
            return '院办分管领导'
        elif self.state == 'db_leader':
            return '党办分管领导'
        elif self.state == 'OPR':
            return '办公室初审'
        else:
            return '书记审核'
    
    def get_type_str(self):
        if self.topic_type == "1":
            return '付款类'
        elif self.topic_type == "2":
            return '经济合同类'
        elif self.topic_type == "3":
            return '项目类'
        elif self.topic_type == "4":
            return '文件类'
        elif self.topic_type == "5":
            return '方案类'
        elif self.topic_type == "7":
            return '招标采购类'
        else:
            return '其他事项'

    def get_pay_type(self):
        if self.pay_type == "1":
            return '合同付款'
        elif self.pay_type == "2":
            return '固定资产/维修维保付款'
        elif self.pay_type == "3":
            return '材料付款'
        elif self.pay_type == "4":
            return '餐补付款'
        elif self.pay_type == "5":
            return '学科经费'
        elif self.pay_type == "6":
            return '科研经费'
        elif self.pay_type == "8":
            return '工会经费'
        else:
            return '一般付款'

    def get_contract_type(self):
        if self.contract_type == "1":
            return '服务类'
        elif self.contract_type == "2":
            return '货物类'
        elif self.contract_type == "3":
            return '工程类'
        else:
            return '其他类'
        
    def get_funding_source(self):
        if self.funding_source == "1":
            return '自有经费'
        elif self.funding_source == "2":
            return '学科经费'
        elif self.funding_source == "3":
            return '科研经费'
        elif self.funding_source == "4":
            return '财政拨款'
        elif self.funding_source == "5":
            return '贴息贷款'
        elif self.funding_source == "6":
            return '专项债券'
        elif self.funding_source == "7":
            return '工会经费'
        else:
            return ""


class TopicsAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
        ('shelve', '搁置'),
    )
    NODE = (
        ('B', '分管领导审批'),
        ('OPR', '办公室初审'),
        ('YB/DB', '党办/院办主任审批'),
        ('Y_D_leader', '党办/院办分管领导审批'),
        ('YZ/SJ', '书记/院长审批'),
        ('yb', '院长办公室'),
        ('transfer', '转会记录'),
        ('yb_result', '院办会议结果'),
        ('db_result', '党办会议结果'),
        ('xz_result', '行政例会会议结果'),
        ('marks', '议题备注'),
        ('db_one_step', '转会第一步'),
        ('db_two_step', '转会第二步'),
        ('db_three_step', '转会第三步'),
        ('db_four_step', '转会第四步'),
    )
    topics_id = models.ForeignKey(
        'Topics',
        verbose_name="议题",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=20, choices=NODE, default='B')

    class Meta:
        verbose_name = '议题审批信息'
        verbose_name_plural = verbose_name


class Topicsattachments(BaseModel):
    """
       议题附件
    """
    topics_number = models.CharField(max_length=128, verbose_name='议题编号')
    file_size = models.CharField(max_length=128, verbose_name='文件大小')
    file_path = models.FileField(default='', upload_to=IssueStampFileName(r'Topics_attachments/'))
    uploader = models.CharField(max_length=128, verbose_name='上传人')
    uploader_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="上传人",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    file_type = models.CharField(default='', max_length=128, verbose_name='文件类型：0：正文，1 附件')
    pdf_path = models.TextField(default='', verbose_name='pdf路径')
    is_deleted = models.BooleanField(default=True, verbose_name='是否可以删除')
    file_name = models.CharField(max_length=128, verbose_name='附件名字')
    source = models.CharField(max_length=32, verbose_name='来源', default='')
    watch_users = models.ManyToManyField('personal_center.User', verbose_name='允许查看的人员',
                                         related_name='attachments_watch_users', blank=True)


class PersonalAttachments(BaseModel):
    """
       个人
    """
    # topics_number = models.CharField(max_length=128, verbose_name='编号')
    file_size = models.CharField(max_length=128, verbose_name='文件大小')
    file_path = models.FileField(default='', upload_to=IssueStampFileName(r'personal_attachments/'))
    uploader_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="上传人",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    pdf_path = models.TextField(default='', verbose_name='pdf路径')
    file_name = models.CharField(max_length=128, verbose_name='附件名字')
    watched_users = models.ManyToManyField('personal_center.User', verbose_name='查看人员',
                                           related_name='personal_attachments_users', blank=True)
    is_secrecy = models.BooleanField(default=False, verbose_name="是否公开")


class Vehicle(BaseModel):
    registration_number = models.CharField(max_length=50, verbose_name='车牌号')
    driver = models.CharField(max_length=50, verbose_name='司机')
    seat = models.CharField(max_length=50, verbose_name='座位')
    start_time = models.DateTimeField(verbose_name='开始时间')
    end_time = models.DateTimeField(verbose_name='结束时间')
    available = models.CharField(max_length=50, verbose_name='是否可用', default="1")


class Driver(BaseModel):
    name = models.CharField(max_length=50, verbose_name='名称')


class VehicleApply(BaseModel):
    STATE = (
        ('draft', '申请中'),
        ('fg', '分管领导已审批'),
        ('ybzr', '车队领导已审批'),
        ('cgb', '车管办分管领导已审批'),
        ('done', '结束'),
        ('refuse', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="申请人",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    state = models.CharField('状态', max_length=10, choices=STATE, default='draft')
    subject = models.CharField(max_length=100, verbose_name='用车事由')
    route = models.CharField(max_length=50, verbose_name='出行路线')
    travelers_numbers = models.CharField(max_length=50, verbose_name='出行人员工号')
    travelers_names = models.CharField(max_length=50, verbose_name='出行人员名字')
    start_time = models.DateTimeField(verbose_name='开始时间')
    end_time = models.DateTimeField(verbose_name='结束时间')
    field_leader_numbers = models.CharField(max_length=100, verbose_name='出行领导工号')
    field_leader = models.CharField(max_length=100, verbose_name='出行领导名字')
    is_fix = models.BooleanField(verbose_name='是否补提', default=False)
    vehicles = models.CharField(max_length=50, verbose_name='车辆', blank=True)
    drivers = models.CharField(max_length=50, verbose_name='司机', blank=True)
    relevance = models.CharField('是否被关联', max_length=50, default='0')
    current_audit_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="当前审批人",
        blank=True,
        null=True,
        related_name='vehicle_apply_current_audit_user',
        on_delete=models.CASCADE)
    already_users = models.ManyToManyField('personal_center.User', verbose_name='已办人员',
                                           related_name='vehicle_apply_already_users', blank=True)
    public_search = models.ForeignKey(
        'PublicSearch',
        verbose_name="搜索表",
        blank=True,
        null=True,
        on_delete=models.CASCADE)

    def get_state_str(self):
        if self.state == "cgb":
            return '结束'
        elif self.state == 'refuse':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return "终止"
        else:
            return '审核中'


class VehicleUseInfo(BaseModel):
    start_time = models.DateTimeField(verbose_name='开始时间')
    end_time = models.DateTimeField(verbose_name='结束时间')
    vehicle = models.ForeignKey(
        'Vehicle',
        verbose_name="车辆信息",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    driver = models.CharField(max_length=50, verbose_name='司机')
    apply_id = models.ForeignKey(
        'VehicleApply',
        verbose_name="车辆申请",
        blank=True,
        null=True,
        on_delete=models.CASCADE)


class VehicleAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('B', '分管领导'),
        ('YB', '车队领导审核'),
        ('CGB', '车管办分管领导审核')
    )

    notice_id = models.ForeignKey(
        'VehicleApply',
        verbose_name="车辆申请",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    node = models.CharField('节点', max_length=10, choices=NODE, default='B')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见")

    class Meta:
        verbose_name = '车辆审批信息'
        verbose_name_plural = verbose_name


class Sequence(BaseModel):
    type = models.CharField('编码', max_length=30, default='')
    sequence = models.IntegerField(verbose_name='当前编码号')
    next_sequence = models.IntegerField(verbose_name='下个编码号')
    topic_year = models.CharField(max_length=50, verbose_name='议题年份', default='2022')


class ConferenceMemo(BaseModel):
    TYPE = (
        ('a', '党委办公会'),
        ('b', '院长办公会'),
        ('c', '党委专题会议'),
        ('d', '院办专题会议'),
        ('e', '行政例会'),
        ('f', '行政公文(对内)'),
        ('g', '党委公文'),
        ('h', '行政公文(对外)'),
        ('i', '共青团'),
    )

    STATE = (
        ('draft', '草稿'),
        ('nine', '科室负责人初审'),
        ('one', '党办/院办主任'),
        ('two', '分管领导'),
        ('three', '指定会签人员'),
        ('four', '会签'),
        ('five', '院长/书记'),
        ('six', '拒绝'),
        ('seven', '结束'),
        ('eight', '分发'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
    )

    number = models.CharField(max_length=50, verbose_name='编号')
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="申请人",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    fg_people = models.ForeignKey(
        'personal_center.User',
        related_name='conference_memo_fg_people',
        verbose_name="分管领导",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    qf_people = models.ForeignKey(
        'personal_center.User',
        related_name='conference_memo_qf_people',
        verbose_name="签发领导",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    drafter = models.CharField(max_length=50, verbose_name='拟稿人')
    drafter_company = models.CharField(max_length=128, verbose_name='拟稿人科室')
    type = models.CharField('类型', max_length=10, choices=TYPE, default='a')
    state = models.CharField('状态', max_length=10, choices=STATE, default='one')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='conference_memo_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='conference_memo_already_audit_users', blank=True)
    document_number = models.CharField(max_length=30, verbose_name='字号/文号')
    document_year = models.CharField(max_length=30, verbose_name='公文年份', default='2022')
    main_company = models.CharField(max_length=100, verbose_name='主送', blank=True)
    vice_company = models.CharField(max_length=100, verbose_name='抄送', blank=True)
    servings = models.CharField(max_length=20, verbose_name='份数', default='')
    conference_memo_text = models.TextField(verbose_name='事由')
    gist = models.TextField(verbose_name='依据', null=True, blank=True)
    # node = models.CharField(max_length=30, verbose_name='节点', blank=True)
    public_search = models.ForeignKey(
        'PublicSearch',
        verbose_name="搜索表",
        blank=True,
        null=True,
        on_delete=models.CASCADE)

    def get_state_str(self):
        if self.state == 'eight':
            return '待分发'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'six':
            return '拒绝'
        elif self.state == 'seven':
            return '结束'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'

    def get_type_str(self):
        if self.type == 'a':
            return '党委会议纪要'
        elif self.type == 'b':
            return '院长办公会会议纪要'
        elif self.type == 'c':
            return '党委专题会议纪要'
        elif self.type == 'd':
            return '院长办公会专题会议纪要'
        elif self.type == 'e':
            return '行政例会简报'
        elif self.type == 'f':
            return '行政公文'
        elif self.type == 'g':
            return '党委公文'
        else:
            return '行政公文'

class ConferenceMemoAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('abstention', '弃权'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('C/D', '拟稿人'),
        ('PRG', '党政办初审'),
        ('YB/DB', '党政办主任核稿'),
        ('YBL/DBL', '分管领导'),
        ('ZXB/LSY', '院办/党办确定会签人员'),
        ('B', '会签'),
        ('YZ/SJ', '签发'),
        ('end', '结束'),
    )
    conference_memo_id = models.ForeignKey(
        'ConferenceMemo',
        verbose_name="会议纪要",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=10, choices=NODE, default='YB/DB')

    class Meta:
        managed = True
        verbose_name = '会议纪要审批信息'
        verbose_name_plural = verbose_name


class ConferenceMemoPeople(BaseModel):
    STATE = (
        ('accept', '未读'),
        ('accepted', '已读'),
    )
    notice_id = models.ForeignKey(
        'ConferenceMemo',
        verbose_name="会议纪要",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='accept')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="人员",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    real_name = models.CharField(default='', max_length=30, verbose_name='姓名')
    signature_picture = models.CharField(default='', max_length=128, verbose_name='签名')

    class Meta:
        verbose_name = '收阅情况'
        verbose_name_plural = verbose_name


class OfficialDocuments(BaseModel):
    TYPE = (
        ('a', '办公室主任审核'),
        ('b', '院长/书记审核'),
        ('c', '分管领导签批'),
        ('d', '科主任传阅'),
        ('e', '结束'),
        ('f', '拒绝'),
        ('g', '待分发'),
        ('h', '申请人选择分管领导'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回')
    )
    STATE = (
        ('a', '留文归档'),
        ('b', '拟办意见'),
        ('c', '党办'),
        ('d', '院办'),
    )

    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="申请人",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='official_documents_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='official_documents_already_audit_users', blank=True)
    leaders = models.ForeignKey('personal_center.User', verbose_name='分管院长', related_name='leader_charge', blank=True, null=True, on_delete=models.SET_NULL)
    type = models.CharField('状态', max_length=10, choices=TYPE, default='a')
    state = models.CharField('类型', max_length=10, choices=STATE, default='a')
    send_number = models.CharField(max_length=30, verbose_name='来文字号')
    recive_number = models.CharField(max_length=30, verbose_name='收文编号')
    send_company = models.CharField(max_length=225, verbose_name='来文单位')
    recive_time = models.DateTimeField(verbose_name='收到日期')
    title = models.TextField(verbose_name='标题')
    content = models.TextField(verbose_name='主要内容')
    annotated_text = models.TextField(verbose_name='标注文本', blank=True)
    remarks = models.TextField(verbose_name='备注', blank=True)
    time_limit = models.CharField(max_length=225, verbose_name='时间期限', blank=True)
    version = models.CharField(max_length=30, verbose_name='上级来文版本', blank=True, default='3')
    increase_Level = models.CharField(max_length=30, verbose_name='是否提升审批等级', blank=True, default='')
    top_flow_id = models.ForeignKey('Topics', verbose_name='上级来文关联院办议题', related_name='TipFlowId', blank=True, null=True, on_delete=models.SET_NULL, default='')
    top_db_flow_id = models.ForeignKey('Topics', verbose_name='上级来文关联院党办议题', related_name='TipDbFlowId', blank=True, null=True, on_delete=models.SET_NULL, default='')
    pay_flow_id = models.ForeignKey('PaymentApproval', verbose_name='关联付款审批', related_name='PayFlowId', blank=True, null=True, on_delete=models.SET_NULL, default='')
    topOrappave = models.CharField(max_length=30, verbose_name='是否申请议题', blank=True, default='')
    public_search = models.ForeignKey(
        'PublicSearch',
        verbose_name="搜索表",
        blank=True,
        null=True,
        on_delete=models.CASCADE)
    uuid = models.CharField(max_length=128, verbose_name='uuid', default='')
    notification_class = models.CharField(max_length=10, verbose_name='通知类', default='0')           # 0: 不是通知类， 1：通知类

    def get_state_str(self):
        if self.type == 'e':
            return '结束'
        elif self.type == 'f':
            return '拒绝'
        elif self.type == 'g':
            return '待分发'
        elif self.type == 'cancel':
            return '作废'
        elif self.type == 'stop':
            return '终止'
        elif self.type == 'recall':
            return '撤回'
        elif self.type == 'd':
            return '科主任传阅'
        else:
            return '审核中'


class OfficialDocumentsAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('YB', '院办主任审批'),
        ('B', '分管领导审批'),
        ('YZ/SJ', '院长/党委书记审批'),
        ('end', '结束'),
        ('SQ', '申请人选择分管领导'),
        ('remarks', '备注'),
    )
    official_documents_id = models.ForeignKey(
        'OfficialDocuments',
        verbose_name="上级来文",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=10, choices=NODE, default='YB')
    img_path = models.CharField('接收人员上传回执', max_length=1000, blank=False, default='')

    class Meta:
        verbose_name = '上级来文审批信息'
        verbose_name_plural = verbose_name

    def get_node_display(self):
        if self.node == 'two':
            return "分管领导"
        elif self.node == 'three':
            return "接收科室回执"
        elif self.node == 'four':
            return "分管领导"
        else:
            ''


class OfficialDocumentsPeople(BaseModel):
    STATE = (
        ('accept', '未读'),
        ('accepted', '已读'),
    )
    notice_id = models.ForeignKey(
        'OfficialDocuments',
        verbose_name="上级来文",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='accept')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="人员",
        blank=False,
        null=False,
        on_delete=models.CASCADE)

    class Meta:
        verbose_name = '收阅情况'
        verbose_name_plural = verbose_name


class PublicSearch(BaseModel):
    TYPE = (('a', '车辆申请'),
            ('b', '议题审批'),
            ('c', '公文审批'),
            ('d', '上级来文'),
            )

    type = models.CharField('类型', max_length=10, choices=TYPE, default='accept')
    content = models.TextField(verbose_name='单据信息')
    apply_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="申请人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='public_search_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='public_search_already_audit_users', blank=True)
    state = models.CharField('状态', max_length=10, default='')


class GatheringApply(BaseModel):
    STATE = (
        ('one', '分管领导审批'),
        ('two', '党政办接受'),
        ('four', '院长审核'),
        ('three', '拒绝'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回'),
        ('five', '结束'),
    )
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="申请人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    apply_company = models.ForeignKey(
        'Company',
        verbose_name="申请科室",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='one')
    date = models.DateTimeField(verbose_name='活动时间')
    field_leader = models.TextField(verbose_name='出席领导')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='gathering_apply_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='gathering_apply_already_audit_users', blank=True)
    people_number = models.IntegerField(verbose_name="参加人数")
    gathering_note = models.TextField(verbose_name='活动内容')
    gathering_place = models.CharField(max_length=32, verbose_name='活动地点', default='')
    uuid = models.CharField(max_length=128, verbose_name='uuid', default='')

    def get_state_str(self):
        if self.state == 'three':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'five':
            return '结束'
        else:
            return '审核中'



class GatheringApplyAuditRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('B', '分管领导意见'),
        ('DB', '党政办接受'),
        ('yz', '院长审核')
    )
    parent_id = models.ForeignKey(
        'GatheringApply',
        verbose_name="申请单",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_note = models.TextField(verbose_name="审批意见", blank=False, default='')
    node = models.CharField('节点', max_length=10, choices=NODE, default='B')

    def get_state_str(self):
        if self.state == 'three':
            return '拒绝'
        elif self.state == 'cancel':
            return '作废'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        elif self.state == 'five':
            return '结束'
        else:
            return '审核中'

class Correspondence(BaseModel):
    TYPE = (
        ('one', '办公室主任审核'),
        ('two', '院长/书记审核'),
        ('three', '分管领导签批'),
        ('four', '科主任传阅'),
        ('five', '结束'),
        ('six', '拒绝'),
        ('seven', '待分发'),
        ('eight', '申请人选择分管领导'),
        ('cancel', '作废'),
        ('stop', '终止'),
        ('recall', '撤回')
    )
    STATE = (
        ('a', '留文归档'),
        ('b', '拟办意见'),
        ('c', '党办'),
        ('d', '院办'),
    )

    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="申请人",
        blank=True,
        null=True,
        on_delete=models.SET_NULL)
    leaders = models.ForeignKey('personal_center.User', verbose_name='分管院长', related_name='correspondence_leader_charge', blank=True,
                                null=True, on_delete=models.SET_NULL)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员',
                                                 related_name='correspondence_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员',
                                                 related_name='correspondence_already_audit_users', blank=True)
    type = models.CharField('状态', max_length=10, choices=TYPE, default='one')
    state = models.CharField('类型', max_length=10, choices=STATE, default='a')
    send_number = models.CharField(max_length=30, verbose_name='来文字号')
    recive_number = models.CharField(max_length=30, verbose_name='收文编号')
    send_company = models.CharField(max_length=225, verbose_name='来文单位')
    recive_time = models.DateTimeField(verbose_name='收到日期')
    title = models.TextField(verbose_name='标题')
    content = models.TextField(verbose_name='主要内容')
    annotated_text = models.TextField(verbose_name='标注文本', blank=True)
    remarks = models.TextField(verbose_name='备注', blank=True)
    time_limit = models.CharField(max_length=225, verbose_name='时间期限', blank=True)
    uuid = models.CharField(max_length=128, verbose_name='uuid', default='')
    flow_type = models.CharField(max_length=20, verbose_name='流程类型', default='wblh')

    def get_state_str(self):
        if self.type == 'five':
            return '结束'
        elif self.type == 'six':
            return '拒绝'
        elif self.type == 'seven':
            return '待分发'
        elif self.type == 'cancel':
            return '作废'
        elif self.type == 'stop':
            return '终止'
        elif self.type == 'recall':
            return '撤回'
        elif self.type == 'four':
            return '科主任传阅'
        else:
            return '审核中'


class CorrespondenceRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '院办主任审批'),
        ('three', '分管领导审批'),
        ('two', '院长/党委书记审批'),
        ('five', '结束'),
        ('eight', '申请人选择分管领导'),
        ('remarks', '备注'),
    )
    official_documents_id = models.ForeignKey(
        'Correspondence',
        verbose_name="外部来函",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=10, choices=NODE, default='YB')

    class Meta:
        verbose_name = '外部来函审批信息'
        verbose_name_plural = verbose_name


class CorrespondencePeople(BaseModel):
    STATE = (
        ('accept', '未读'),
        ('accepted', '已读'),
    )
    notice_id = models.ForeignKey(
        'Correspondence',
        verbose_name="外部来函",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='accept')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="人员",
        blank=False,
        null=False,
        on_delete=models.CASCADE)

    class Meta:
        verbose_name = '收阅情况'
        verbose_name_plural = verbose_name


class PaymentApproval(BaseModel):
    STATE = (
        ('one', '科室负责人'),
        ('two', '分管领导'),
        ('three', '财务科负责人'),
        ('four', '总会计师'),
        ('five', '会计支付'),
        ('six', '科教科审核'),
        ('stop', '中止'),
        ('eight', '拒绝'),
        ('recall', '撤回'),
        ('end', '结束'),
    )
    PayType = (
        ('1', '合同付款'),
        ('2', '固定资产/维修维保付款'),
        ('3', '材料付款'),
        ('4', '餐补付款'),
        ('5', '学科经费'),
        ('6', '科研经费'),
        ('7', '一般付款'),
        ('8', '工会经费'),
    )
    Category = (
        ('1', '专利申请费'),
        ('2', '外出参加学术会议'),
        ('3', '外出参加技能培训'),
        ('4', '外出进修学习'),
        ('5', '教学设备'),
        ('6', '教授劳务费'),
        ('7', '教授接待费'),
        ('8', '版面费'),
        ('9', '其他')
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL, default='')
    company = models.ForeignKey('Company', verbose_name="申请科室", blank=False, null=True, on_delete=models.CASCADE)
    topics_id = models.ForeignKey('Topics', verbose_name='关联议题流程', related_name='RelatedIssueProcess', blank=True, null=True, on_delete=models.SET_NULL)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='CurrentReviewer', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='AlreadyReviewer', blank=True)
    state = models.CharField('状态', max_length=10, choices=STATE, default='')
    Payee = models.CharField(max_length=255, verbose_name='收款单位', default='')
    receiving_account = models.CharField(max_length=255, verbose_name='收款账号', default='')
    opening_bank = models.CharField(max_length=225, verbose_name='开户行', default='')
    title = models.CharField(max_length=225, verbose_name='付款事由', default='')
    source = models.CharField(max_length=225, verbose_name='经费来源', default='')
    total_money = models.CharField(max_length=100, verbose_name='付款总金额', default='')
    daxie = models.CharField(max_length=255, verbose_name='大写', default='')
    pay_type = models.CharField('付款类型', max_length=10, choices=PayType, default='')
    expense_category = models.CharField('费用类别', max_length=10, choices=Category, default='')
    node = models.CharField(max_length=225, verbose_name='备注', default='')
    fj_number = models.CharField(max_length=128, verbose_name='uuid', default='', null=True)
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    beforehand_parent = models.ForeignKey('NewFlowLogic.BeforehandReception', verbose_name="公务（外宾）接待事前审批", blank=True, null=True, on_delete=models.SET_NULL, default='')
    reception_parent = models.ForeignKey('NewFlowLogic.ReceptionChecklist', verbose_name="公务(外宾)接待清单审批", blank=True, null=True, on_delete=models.SET_NULL, default='')

    def get_state_str(self):
        if self.state == 'end':
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        else:
            return '审核中'
    def get_expense_type(self):
        if self.expense_category == '1':
            return '专利申请费'
        elif self.expense_category == '2':
            return '外出参加学术会议'
        elif self.expense_category == '3':
            return '外出参加技能培训'
        elif self.expense_category == '4':
            return '外出进修学习'
        elif self.expense_category == '5':
            return '教学设备'
        elif self.expense_category == '6':
            return '教授劳务费'
        elif self.expense_category == '7':
            return '教授接待费'
        elif self.expense_category == '8':
            return '版面费'
        else:
            return '其他'

class PaymentApprovalRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人'),
        ('two', '分管领导'),
        ('three', '财务科负责人'),
        ('four', '总会计师'),
        ('five', '会计支付'),
        ('six', '科教科审核'),
    )
    official_documents_id = models.ForeignKey(
        'PaymentApproval',
        verbose_name="付款流程",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=10, choices=NODE, default='YB')

    class Meta:
        verbose_name = '付款流程'
        verbose_name_plural = verbose_name


class ContractApproval(BaseModel):
    STATE = (
        ('one', '审计科'),
        ('two', '财务科'),
        ('three', '监察室'),
        ('four', '法人审批'),
        ('five', '院办盖章'),
        ('six', '上传协议'),
        ('seven', '申请人上传合同'),
        ('stop', '中止'),
        ('eight', '拒绝'),
        ('recall', '撤回'),
        ('end', '结束'),
    )
    apply_user = models.ForeignKey(
        'personal_center.User',
        verbose_name="申请人",
        blank=True,
        null=True,
        on_delete=models.SET_NULL, default='')
    topics_id = models.ForeignKey('Topics', verbose_name='关联议题流程', related_name='ContractIssueProcess', blank=True, null=True, on_delete=models.SET_NULL)
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='ContractReviewer', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='ContractAlreadyReviewer', blank=True)
    state = models.CharField('状态', max_length=10, choices=STATE, default='')
    title = models.CharField(max_length=225, verbose_name='付款事由', default='')
    fj_number = models.CharField(max_length=128, verbose_name='uuid', default=uuid.uuid4(), null=True)
    whether_upload = models.CharField('是否上传', max_length=10, default='0')

    def get_state_str(self):
        if self.state == 'end':
            return '结束'
        elif self.state == 'eight':
            return '拒绝'
        elif self.state == 'stop':
            return '终止'
        elif self.state == 'recall':
            return '撤回'
        else:
            return '审核中'

class ContractApprovalRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('negative', '立项科室'),
        ('zero', '分管领导'),
        ('one', '审计科'),
        ('two', '财务科'),
        ('three', '监察室'),
        ('four', '法人审批'),
        ('five', '院办盖章'),
    )
    official_documents_id = models.ForeignKey(
        'ContractApproval',
        verbose_name="合同会签流程",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey(
        'personal_center.User',
        verbose_name="审批人",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=10, choices=NODE, default='YB')

    class Meta:
        verbose_name = '合同会签流程'
        verbose_name_plural = verbose_name

class ManagementLoginRecords(BaseModel):
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL, default='')
    code = models.CharField('验证码', max_length=30, default='')
    overdue = models.CharField('是否过期', max_length=10, default='0')
    login_time = models.DateTimeField(blank=True, null=True, verbose_name='登陆时间')